<?php
class Tags
{
    public static function getTagsMap(){
        $url = AC::getProtocolUriByOS(AC::$cdn_url_d);
        $tags_map = array(
            "tags"    =>    array(
                array(
                    "name" => "热门属性",
                    "desc" => "精选热门属性",
                    "type" => "8",
                    "icon" => "{$url}/web/static/tag/icon/default/hot.png",
                    "tag_list"    =>    array(
                        array("id" => "100013", "name" => "萝莉",  "count" => "0", "type" => "1"),
                        array("id" => "100010", "name" => "逗逼",  "count" => "0", "type" => "1"),
                        array("id" => "100015", "name" => "女王",  "count" => "0", "type" => "1"),
                        array("id" => "100018", "name" => "学生党",  "count" => "0", "type" => "1"),
                        array("id" => "100020", "name" => "女汉纸",  "count" => "0", "type" => "1"),
                        array("id" => "100022", "name" => "二货",  "count" => "0", "type" => "1"),
                        array("id" => "100028", "name" => "小清新",  "count" => "0", "type" => "1"),
                        array("id" => "100033", "name" => "吃货",  "count" => "0", "type" => "2"),
                        array("id" => "100039", "name" => "拍照",   "count" => "0", "type" => "2"),
                        array("id" => "100041", "name" => "听歌",  "count" => "0", "type" => "2"),
                        array("id" => "100043", "name" => "动漫",  "count" => "0", "type" => "2"),
                        array("id" => "100062", "name" => "狂吃不胖",   "count" => "0", "type" => "4"),
                        array("id" => "100063", "name" => "笑点低",   "count" => "0", "type" => "4"),
                        array("id" => "100064", "name" => "双重性格",  "count" => "0", "type" => "4"),
                        array("id" => "100078", "name" => "呆萌",   "count" => "0", "type" => "5"),
                        array("id" => "100086", "name" => "萌萌哒",  "count" => "0", "type" => "5"),
                    )
                ),
                array(
                    "name" => "个人属性",
                    "desc" => "来曝光下你的属性",
                    "type" => "1",
                    "icon" => "{$url}/web/static/tag/icon/default/1.png",
                    "tag_list"    =>    array(
                        array("id" => "100013", "name" => "萝莉",  "count" => "0", "type" => "1"),
                        array("id" => "100014", "name" => "辣妈",   "count" => "0", "type" => "1"),
                        array("id" => "100015", "name" => "女王",  "count" => "0", "type" => "1"),
                        array("id" => "100016", "name" => "暖男",  "count" => "0", "type" => "1"),
                        array("id" => "100017", "name" => "段子手",  "count" => "0", "type" => "1"),
                        array("id" => "100018", "name" => "学生党",  "count" => "0", "type" => "1"),
                        array("id" => "100010", "name" => "逗逼",  "count" => "0", "type" => "1"),
                        array("id" => "100020", "name" => "女汉纸",  "count" => "0", "type" => "1"),
                        array("id" => "100021", "name" => "粉粉er",  "count" => "0", "type" => "1"),
                        array("id" => "100022", "name" => "二货",  "count" => "0", "type" => "1"),
                        array("id" => "100023", "name" => "小鲜肉",   "count" => "0", "type" => "1"),
                        array("id" => "100024", "name" => "单身狗",  "count" => "0", "type" => "1"),
                        array("id" => "100025", "name" => "文艺青年",  "count" => "0", "type" => "1"),
                        array("id" => "100026", "name" => "伪男",  "count" => "0", "type" => "1"),
                        array("id" => "100027", "name" => "正太",  "count" => "0", "type" => "1"),
                        array("id" => "100028", "name" => "小清新",  "count" => "0", "type" => "1")
                    )
                ),
                array(
                    "name" => "星座年代",
                    "desc" => "让我一秒读透你",
                    "type" => "7",
                    "icon" => "{$url}/web/static/tag/icon/default/7.png",
                    "tag_list"    =>    array(
                        array("id" => "100109", "name" => "白羊座", "count" => "0", "type" => "7"),
                        array("id" => "100110", "name" => "金牛座", "count" => "0", "type" => "7"),
                        array("id" => "100111", "name" => "双子座", "count" => "0", "type" => "7"),
                        array("id" => "100112", "name" => "巨蟹座", "count" => "0", "type" => "7"),
                        array("id" => "100113", "name" => "狮子座", "count" => "0", "type" => "7"),
                        array("id" => "100114", "name" => "处女座", "count" => "0", "type" => "7"),
                        array("id" => "100115", "name" => "天秤座", "count" => "0", "type" => "7"),
                        array("id" => "100116", "name" => "天蝎座", "count" => "0", "type" => "7"),
                        array("id" => "100117", "name" => "射手座", "count" => "0", "type" => "7"),
                        array("id" => "100118", "name" => "摩羯座", "count" => "0", "type" => "7"),
                        array("id" => "100119", "name" => "双鱼座", "count" => "0", "type" => "7"),
                        array("id" => "100120", "name" => "水瓶座", "count" => "0", "type" => "7"),
                        array("id" => "100121", "name" => "90后",  "count" => "0", "type" => "7"),
                        array("id" => "100122", "name" => "95后",  "count" => "0", "type" => "7"),
                        array("id" => "100123", "name" => "00后",  "count" => "0", "type" => "7"),
                        array("id" => "100124", "name" => "80后",  "count" => "0", "type" => "7")
                    )
                ),
                array(
                    "name" => "兴趣爱好",
                    "desc" => "有爱才有好基友",
                    "type" => "2",
                    "icon" => "{$url}/web/static/tag/icon/default/2.png",
                    "tag_list"    =>    array(
                        array("id" => "100029", "name" => "聘关系",  "count" => "0", "type" => "2"),
                        array("id" => "100030", "name" => "手工DIY",   "count" => "0", "type" => "2"),
                        array("id" => "100031", "name" => "追剧",   "count" => "0", "type" => "2"),
                        array("id" => "100032", "name" => "麦霸",  "count" => "0", "type" => "2"),
                        array("id" => "100033", "name" => "吃货",  "count" => "0", "type" => "2"),
                        array("id" => "100034", "name" => "Cosplay",  "count" => "0", "type" => "2"),
                        array("id" => "100035", "name" => "古风",  "count" => "0", "type" => "2"),
                        array("id" => "100036", "name" => "宫斗",  "count" => "0", "type" => "2"),
                        array("id" => "100037", "name" => "写文",  "count" => "0", "type" => "2"),
                        array("id" => "100038", "name" => "手绘",  "count" => "0", "type" => "2"),
                        array("id" => "100039", "name" => "拍照",   "count" => "0", "type" => "2"),
                        array("id" => "100040", "name" => "游戏",  "count" => "0", "type" => "2"),
                        array("id" => "100041", "name" => "听歌",  "count" => "0", "type" => "2"),
                        array("id" => "100042", "name" => "同人",  "count" => "0", "type" => "2"),
                        array("id" => "100043", "name" => "动漫",  "count" => "0", "type" => "2"),
                        array("id" => "100044", "name" => "购物狂",  "count" => "0", "type" => "2")
                    )
                ),
                array(
                    "name" => "N次元",
                    "desc" => "你是几次元？",
                    "type" => "3",
                    "icon" => "{$url}/web/static/tag/icon/default/3.png",
                    "tag_list"    =>    array(
                        array("id" => "100045", "name" => "中二病",  "count" => "0", "type" => "3"),
                        array("id" => "100046", "name" => "ACG",   "count" => "0", "type" => "3"),
                        array("id" => "100047", "name" => "腐女",   "count" => "0", "type" => "3"),
                        array("id" => "100048", "name" => "傲娇",  "count" => "0", "type" => "3"),
                        array("id" => "100049", "name" => "御宅族",  "count" => "0", "type" => "3"),
                        array("id" => "100050", "name" => "黑长直",  "count" => "0", "type" => "3"),
                        array("id" => "100051", "name" => "BL",  "count" => "0", "type" => "3"),
                        array("id" => "100052", "name" => "GL",  "count" => "0", "type" => "3"),
                        array("id" => "100053", "name" => "KUSO",  "count" => "0", "type" => "3"),
                        array("id" => "100054", "name" => "耽美",  "count" => "0", "type" => "3"),
                        array("id" => "100055", "name" => "娇蛮",   "count" => "0", "type" => "3"),
                        array("id" => "100056", "name" => "毒舌",  "count" => "0", "type" => "3"),
                        array("id" => "100057", "name" => "追番",  "count" => "0", "type" => "3"),
                        array("id" => "100058", "name" => "手办",  "count" => "0", "type" => "3"),
                        array("id" => "100059", "name" => "软妹纸",  "count" => "0", "type" => "3"),
                        array("id" => "100060", "name" => "CG党",  "count" => "0", "type" => "3")
                    )
                ),
                array(
                    "name" => "神秘能力",
                    "desc" => "地球好危险，让我来拯救",
                    "type" => "4",
                    "icon" => "{$url}/web/static/tag/icon/default/4.png",
                    "tag_list"    =>    array(
                        array("id" => "100061", "name" => "学渣",  "count" => "0", "type" => "4"),
                        array("id" => "100062", "name" => "狂吃不胖",   "count" => "0", "type" => "4"),
                        array("id" => "100063", "name" => "笑点低",   "count" => "0", "type" => "4"),
                        array("id" => "100064", "name" => "双重性格",  "count" => "0", "type" => "4"),
                        array("id" => "100065", "name" => "学霸",  "count" => "0", "type" => "4"),
                        array("id" => "100066", "name" => "嘲讽技能",  "count" => "0", "type" => "4"),
                        array("id" => "100067", "name" => "蛇精病",  "count" => "0", "type" => "4"),
                        array("id" => "100068", "name" => "装逼于无形",  "count" => "0", "type" => "4"),
                        array("id" => "100069", "name" => "晒不黑",  "count" => "0", "type" => "4"),
                        array("id" => "100070", "name" => "考试必过",  "count" => "0", "type" => "4"),
                        array("id" => "100071", "name" => "脑洞大开",   "count" => "0", "type" => "4"),
                        array("id" => "100072", "name" => "第六感准",  "count" => "0", "type" => "4"),
                        array("id" => "100073", "name" => "过目不忘",  "count" => "0", "type" => "4"),
                        array("id" => "100074", "name" => "脾气好",  "count" => "0", "type" => "4"),
                        array("id" => "100075", "name" => "颜文字高手",  "count" => "0", "type" => "4"),
                        array("id" => "100076", "name" => "特别能吃辣",  "count" => "0", "type" => "4")
                    )
                ),
                array(
                    "name" => "网络热词",
                    "desc" => "你躺着中枪了吗？",
                    "type" => "5",
                    "icon" => "{$url}/web/static/tag/icon/default/5.png",
                    "tag_list"    =>    array(
                        array("id" => "100077", "name" => "有钱任性",  "count" => "0", "type" => "5"),
                        array("id" => "100078", "name" => "呆萌",   "count" => "0", "type" => "5"),
                        array("id" => "100079", "name" => "重口味",   "count" => "0", "type" => "5"),
                        array("id" => "100080", "name" => "安静美男子",  "count" => "0", "type" => "5"),
                        array("id" => "100081", "name" => "霸道总裁",  "count" => "0", "type" => "5"),
                        array("id" => "100082", "name" => "逼格高",  "count" => "0", "type" => "5"),
                        array("id" => "100083", "name" => "屌丝逆袭",  "count" => "0", "type" => "5"),
                        array("id" => "100084", "name" => "爱吃辣条",  "count" => "0", "type" => "5"),
                        array("id" => "100085", "name" => "买买买",  "count" => "0", "type" => "5"),
                        array("id" => "100086", "name" => "萌萌哒",  "count" => "0", "type" => "5"),
                        array("id" => "100087", "name" => "没吃药",   "count" => "0", "type" => "5"),
                        array("id" => "100088", "name" => "不作不死",  "count" => "0", "type" => "5"),
                        array("id" => "100089", "name" => "膝盖碎了",  "count" => "0", "type" => "5"),
                        array("id" => "100090", "name" => "EXO",  "count" => "0", "type" => "5"),
                        array("id" => "100091", "name" => "TFboys",  "count" => "0", "type" => "5"),
                        array("id" => "100092", "name" => "伐开心",  "count" => "0", "type" => "5")
                    )
                ),
                array(
                    "name" => "什么控",
                    "desc" => "你沉浸在哪个控里面？",
                    "type" => "6",
                    "icon" => "{$url}/web/static/tag/icon/default/6.png",
                    "tag_list"    =>    array(
                        array("id" => "100093", "name" => "大叔控",  "count" => "0", "type" => "6"),
                        array("id" => "100094", "name" => "颜控",   "count" => "0", "type" => "6"),
                        array("id" => "100095", "name" => "声控",   "count" => "0", "type" => "6"),
                        array("id" => "100096", "name" => "自拍控",  "count" => "0", "type" => "6"),
                        array("id" => "100097", "name" => "游戏控",  "count" => "0", "type" => "6"),
                        array("id" => "100098", "name" => "猫耳控",  "count" => "0", "type" => "6"),
                        array("id" => "100099", "name" => "百合控",  "count" => "0", "type" => "6"),
                        array("id" => "100100", "name" => "短发控",  "count" => "0", "type" => "6"),
                        array("id" => "100101", "name" => "制服控",  "count" => "0", "type" => "6"),
                        array("id" => "100102", "name" => "正太控",  "count" => "0", "type" => "6"),
                        array("id" => "100103", "name" => "万控",   "count" => "0", "type" => "6"),
                        array("id" => "100104", "name" => "星座控",  "count" => "0", "type" => "6"),
                        array("id" => "100105", "name" => "御宅控",  "count" => "0", "type" => "6"),
                        array("id" => "100106", "name" => "明星控",  "count" => "0", "type" => "6"),
                        array("id" => "100107", "name" => "丝袜控",  "count" => "0", "type" => "6"),
                        array("id" => "100108", "name" => "粉红控",  "count" => "0", "type" => "6")
                    )
                )
            ),
            'counts'    =>    8
        );
        return $tags_map;
    }
    
    public static $tags_hotdiary_label = array(
        "SSet:hotdiary:cat_1" => array("100045" => "中二病",   "100046" => "ACG", "100047" => "腐女", "100048" => "傲娇", "100049" => "御宅族", "100050" => "黑长直", "100051" => "BL", "100052" => "GL", "100034" => "Cosplay", "100030" => "手工DIY", "100036" => "宫斗", "100098" => "猫耳控", "100099" => "百合控", "100053" => "KUSO", "100054" => "耽美", "100055" => "娇蛮", "100056" => "毒舌", "100057" => "追番", "100058" => "手办", "100059" => "软妹纸", "100060" => "CG党", "100042" => "同人", "100043" => "动漫", "100075" => "颜文字高手", "100038" => "手绘", "100097" => "游戏控", "100105" => "御宅控", "100102" => "正太控", "100107" => "丝袜控", "100093" => "大叔控", "100094" => "颜控", "100095" => "声控", "100101" => "制服控", "100078" => "呆萌", "100086" => "萌萌哒", "100074" => "脾气好"),
        "SSet:hotdiary:cat_2" => array("100013" => "萝莉",    "100016" => "暖男", "100017" => "段子手", "100018" => "学生党", "100010" => "逗逼", "100020" => "女汉纸", "100063" => "笑点低", "100103" => "万控", "100108" => "粉红控", "100021" => "粉粉er", "100022" => "二货", "100023" => "小鲜肉", "100024" => "单身狗", "100025" => "文艺青年", "100026" => "伪男", "100027" => "正太", "100028" => "小清新", "100061" => "学渣", "100065" => "学霸", "100070" => "考试必过"),
        "SSet:hotdiary:cat_3" => array("100109" => "白羊座",   "100110" => "金牛座", "100111" => "双子座", "100112" => "巨蟹座", "100113" => "狮子座", "100114" => "处女座", "100115" => "天秤座", "100116" => "天蝎座", "100117" => "射手座", "100118" => "摩羯座", "100119" => "双鱼座", "100120" => "水瓶座", "100121" => "90后", "100122" => "95后", "100123" => "00后", "100124" => "80后", "100064" => "双重性格", "100072" => "第六感准", "100104" => "星座控"),
        "SSet:hotdiary:cat_4" => array("100029" => "聘关系",   "100031" => "追剧", "100032" => "麦霸", "100033" => "吃货", "100035" => "古风", "100037" => "写文", "100039" => "拍照", "100040" => "游戏", "100041" => "听歌", "100090" => "EXO", "100091" => "TFboys", "100106" => "明星控", "100080" => "安静美男子", "100081" => "霸道总裁", "100096" => "自拍控", "100076" => "特别能吃辣", "100062" => "狂吃不胖"),
        "SSet:hotdiary:cat_5" => array("100077" => "有钱任性",  "100079" => "重口味", "100082" => "逼格高", "100083" => "屌丝逆袭", "100084" => "爱吃辣条", "100087" => "没吃药", "100088" => "不作不死", "100089" => "膝盖碎了", "100092" => "伐开心", "100100" => "短发控", "100066" => "嘲讽技能", "100067" => "蛇精病", "100068" => "装逼于无形", "100069" => "晒不黑", "100071" => "脑洞大开", "100073" => "过目不忘"),
        "SSet:hotdiary:cat_6" => array("100014" => "辣妈",     "100015" => "女王", "100085" => "买买买", "100044" => "购物狂")
    );
    
    public static $tags_group_map = array(
            1 => array(100014,100015,100016,100024,100025,100029,100054,100066,100067,100072,100088,100099,100105,100092,100026,100064),
            2 => array(100018,100061,100065,100070,100073),
            3 => array(100020,100024,100064,100077,100080,100089,100092,100023),
            4 => array(100014,100030,100035,100039,100093,100096,100094,100100,100038,100058),
            5 => array(100109,100110,100111,100112,100113,100114,100115,100116,100117,100118,100119,100120,100121,100122,100123,100124,100104,100103),
            6 => array(100087,100089,100103,100017,100010,100022,100063,100064,100071),
            7 => array(100085,100108,100044,100069),
            8 => array(100014,100015,100108,100020),
            9 => array(100042,100043,100044,100045,100046,100047,100048,100049,100050,100051,100052,100013,100034,100053,100054,100055,100056,100057,100058,100059,100060,100071,100075,100086,100097),
            10 => array(100081,100080,100090,100091,100093,100101,100102,100106,100021,100094),
            11 => array(100018,100061,100065),
            12 => array(100076,100079,100084,100025,100033,100062),
            13 => array(100075,100078,100086,100098,100102),
            14 => array(100070,100073,100061,100065,100018),
            15 => array(100090,100091,100099,100037,100042,100054,100051,100052,100047,100035),
            17 => array(100082,100025,100028,100032,100041,100095),
            18 => array(100036,100097,100040),
            19 => array(100075,100076,100080,100084,100087,100103,100017,100066),
            26 => array(100080,100081,100083,100092,100093,100016,100023,100072),
            27 => array(100078,100083,100092,100099,100016,100020,100023,100026,100074,100056),
            28 => array(100021,100104,100072),
            29 => array(100079,100020),
            31 => array(100077,100082,100085,100044,100069),
            32 => array(100082,100085,100107,100062),
            33 => array(100077,100082,100085,100100,100030,100050),
            34 => array(100077,100082,100085,100101,100107),
            35 => array(100077,100082,100085,100107),
            36 => array(100077,100082,100085,100107),
            37 => array(100096,100039,100068),
            38 => array(100082,100085,100044,100077),
            39 => array(100076,100082,100025,100028),
            40 => array(100082,100025,100031,100057),
            41 => array(100018,100061,100065),
            42 => array(100076,100062),
            43 => array(100075,100084,100087,100017,100010,100022)
    );
    
    public static function getUnionKeys($tagsstr) {
        $key_arr = array();
        foreach ($tagsstr as $value) {
            foreach (Tags::$tags_hotdiary_label as $key => $val) {
                if (in_array(trim($value), $val) && !in_array($key, $key_arr)) {
                    $key_arr[] = strval($key);
                }
            }
        }
        
        return $key_arr;
    }
    
	public static function getTagInfo($name){
	    $tag_list = self::getTagsMap();
	    $tag_list = $tag_list['tags'];
        $result = array();
    	foreach ($tag_list as $value){
            foreach ($value['tag_list'] as $val){
                if (($name == $val['name'])){
                    $result = array(
                            'id'    =>    $val['id'],
                            'name'    =>    $val['name'],
                            'count'    =>    $val['count'],
                            'type'    =>    $val['type'],
                    );
                    break;
                }
            }
        }
        return $result;
	}
	
	public static function getTagInfoByTagId($tag_id){
        $tag_list = self::getTagsMap();
        $tag_list = $tag_list['tags'];
	    $result = array();
	    foreach ($tag_list as $value){
	        foreach ($value['tag_list'] as $val){
	            if (($tag_id == $val['id'])){
	                $result = array(
	                        'id'    =>    $val['id'],
	                        'name'    =>    $val['name'],
	                        'count'    =>    $val['count'],
	                        'type'    =>    $val['type'],
	                );
	                break;
	            }
	        }
	    }
	    return $result;
	}
	
	public static function getTagsByGroupId($group_id){
	    $tagIds = Tags::$tags_group_map[$group_id];
	    if (empty($tagIds)){
	        return array();
	    }
	    
	    $tagInfo = $result = array();
	    foreach ($tagIds as $val){
	        $tagInfo = Tags::getTagInfoByTagId($val);
	        if (empty($tagInfo)){
	            continue;
	        }
	        $result[] = $tagInfo;
	    }
	    
	    return $result;
	}
	
	public static function getGroupsByTag($tag_id){
        $tags_group_map = Tags::$tags_group_map;
        $result = array();
        $keys = array_keys($tags_group_map);
        $counts= count($keys);
        for ($i = 0 ; $i < $counts; $i ++){
            if (in_array($tag_id, $tags_group_map[$keys[$i]])){
                $result[] = $keys[$i];
            }
        }
        return $result;
    }
}